#!/bin/sh

. scripts/functions

#
# Run a simple backup
#   to a tape then restore it, we do that twice to ensure that
#   we can correctly append to a tape.
# We also use the purge and the relabel commands as
#   well as a pile of status storage commands.
#
TestName="backup-to-null"
JobName=backuptonull

scripts/cleanup
scripts/copy-fifo-confs

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list

change_jobname NightlySave $JobName
start_test


# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
@#setdebug level=200 storage=Dummy
label storage=Dummy volume=TestVolume001 slot=0 pool=Default
run job=$JobName yes
status storage=Dummy
@sleep 1
wait
@sleep 3
messages
quit
END_OF_DATA

run_susan
check_for_zombie_jobs storage=Dummy

#
# Now do a second backup after making a few changes
#
echo "test test" > ${BackupDirectory}/xxx

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out ${cwd}/tmp/log2.out
list volumes
run job=$JobName yes
wait
list volumes
@sleep 3
messages
quit
END_OF_DATA

run_bconsole
check_for_zombie_jobs storage=Dummy
stop_susan

grep "^  Termination: *Backup OK" ${cwd}/tmp/log1.out 2>&1 >/dev/null
bstat=$?
grep "^  Termination: *Backup OK" ${cwd}/tmp/log2.out 2>&1 >/dev/null
dstat=$?

# not yet implemented
rstat=0

end_test

